<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增轮播图列表')" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-banner-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">轮播图：</label>
                <div class="col-sm-8">
                    <input type="hidden" name="bannerUrl">
                    <div class="file-loading">
                        <input class="form-control file-upload" id="bannerUrl" name="file" type="file">
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">轮播图顺序：</label>
                <div class="col-sm-8">
                    <input id="bannerSequence" name="bannerSequence" class="form-control" type="number" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">状态：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('core_deleted')}">
                        <input type="radio" th:id="${'bannerStatus_' + dict.dictCode}" name="bannerStatus" th:value="${dict.dictValue}" th:checked="${dict.default}">
                        <label th:for="${'bannerStatus_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-fileinput-js"/>
    <script th:inline="javascript">
        var prefix = ctx + "core/banner"
        $("#form-banner-add").validate({
            focusCleanup: true,
            rules : {
                bannerSequence:{
                    remote :{
                        url: prefix+"/getBannerSequence",
                        type:"POST",
                        data:{
                           bannerSequence:function () {
                                return $("#bannerSequence").val();
                            }
                        }
                    }
                }
            },
            messages: {
                bannerSequence:{
                    remote:"该排序号已存在"
                }
            }

        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-banner-add').serialize());
            }
        }

        $(".file-upload").fileinput({
            uploadUrl: ctx+'/common/upload',
            maxFileCount: 1,
            autoReplace: true
        }).on('fileuploaded', function (event, data, previewId, index) {
            $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
        }).on('fileremoved', function (event, id, index) {
            $("input[name='" + event.currentTarget.id + "']").val('')
        })
    </script>
</body>
</html>